// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import VueI18n from 'vue-i18n'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store'
import './assets/css/icon.css'
import './components/common/directives'
import 'babel-polyfill'
import * as echarts from 'echarts'
import china from '../src/assets/json/china.json'
import dataV from '@jiaminghi/data-view'
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import VueUeditorWrap from 'vue-ueditor-wrap'
import BaiduMap from 'vue-baidu-map'
Vue.component('VueUeditorWrap', VueUeditorWrap)

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: '5GQmS2CXm9SRZT86DRzXjrsFDtc2YG9z'
})

Vue.use(mavonEditor)
Vue.use(dataV)
echarts.registerMap('china', china)
Vue.prototype.$echarts = echarts
// 设置反向代理，前端请求默认发送到 http://localhost:8088/api,即后端端口号为8088
var axios = require('axios')
axios.defaults.baseURL = 'http://47.96.28.215:8088/api'
// axios.defaults.baseURL = 'http://118.31.71.148:8088/api'
// axios.defaults.baseURL = 'http://localhost:8088/api'
// 同源策略
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'

// // 设置携带cookie信息
// axios.defaults.withCredentials = true
// 全局注册，之后可在其他组件中通过 this.$axios 发送数据
Vue.prototype.$axios = axios
Vue.config.productionTip = false
Vue.use(VueI18n)
Vue.use(ElementUI)
Vue.use(store)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  render: h => h(App),
  router,
  store,
  components: { App },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    console.log('router.beforeEach(): ' + JSON.stringify(store.state.user))
    if (store.state.token) {
      console.log('coming to next ')
      next()
    } else {
      next({
        path: '/login',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next()
  }
})
